<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请类型">
        <el-select v-model="queryParams.jrProductType" placeholder="请选择">
          <el-option label="租房分期" value="1"></el-option>
          <el-option label="收房贷" value="2"></el-option>
          <el-option label="应收租约保理" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请状态">
        <el-select v-model="queryParams.applyState" placeholder="请选择">
          <el-option label="申请中" value="1"></el-option>
          <el-option label="初审通过(待复审)" value="2"></el-option>
          <el-option label="初审不通过" value="3"></el-option>
          <el-option label="复审通过" value="4"></el-option>
          <el-option label="复审不通过" value="5"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="起租日期">
        <div class="block">
          <el-date-picker v-model="queryParams.startDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">

          </el-date-picker>至
          <el-date-picker v-model="queryParams.endDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd">
          </el-date-picker>
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="installmentList" @selection-change="handleSelectionChange">
      <el-table-column label="申请合同号" prop="applyOrderNo" width="120" />
      <el-table-column label="贷款信息" prop="loanMessage" width="120" />
      <el-table-column label="申请类型" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.jrProductType==1">
            租房分期
          </div>
          <div v-else-if="scope.row.jrProductType==2">
            收房贷
          </div>
          <div v-else>
            应收租约保理
          </div>
        </template>
      </el-table-column>
      <el-table-column label="借款金额" width="150">
        <template slot-scope="scope">
          {{ scope.row.loanAmount }}元
        </template>
      </el-table-column>
      <el-table-column label="借款期限" width="150">
        <template slot-scope="scope">
          {{ scope.row.monthLimit }}月
        </template>
      </el-table-column>
      <el-table-column label="申请日期" prop="createTime" width="120" />
      <el-table-column label="资金方" prop="companyName" width="120" />
      <el-table-column label="申请状态" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.applyState==1">
            申请中
          </div>
          <div v-else-if="scope.row.applyState==2">
            初审通过(待复审)
          </div>
          <div v-else-if="scope.row.applyState==3">
            初审不通过
          </div>
          <div v-else-if="scope.row.applyState==4">
            复审通过
          </div>
          <div v-else>
            复审不通过
          </div>
        </template>
      </el-table-column>

      <el-table-column label=驳回原因 prop="auditMemo" width="120" />
      <el-table-column label="操作" width="300">
        <template slot-scope="scope">
          <div v-if="scope.row.applyState==1">
            <el-button @click="shenhe(scope.row)" type="text" size="small">审核</el-button>
          </div>
          <div v-else-if="scope.row.applyState==2">
            <el-button @click="shenhe(scope.row)" type="text" size="small">审核</el-button>
          </div>
          <div v-else-if="scope.row.applyState==3">
            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>

          </div>
          <div v-else-if="scope.row.applyState==4">
            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>
          </div>
          <div v-else-if="scope.row.applyState==5">

            <el-button @click="cha(scope.row)" type="text" size="small">查看</el-button>
          </div>
          <div v-else>
            审核中
          </div>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--    查看-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible1"
      width="80%">
      <h1>|申请主题信息</h1><br>
      公寓名称：{{zf.premiseName}}<br><br>
      公司名称：{{zf.premiseName}}
      联系人：{{zf.premiseName}}<br><br>
      手机号：{{contas.signUserMobile}}
      申请时间：{{zf.createTime}}<br><br>
      法人姓名：{{contas.signUserName}}
      法人身份证：{{contas.signUserIdCard}}<br><br>
      公司地址：{{contas.cqAddress}}
      账户类型：<br><br>
      账户：
      开户行：<br>
      法人身份证：
      <h1>|贷款详细信息</h1><br>
      租客姓名：{{zf.tenantName}}
      租客手机号：{{zf.tenantPhone}}
      承租房间：{{zf.roomName}}<br><br>
      月租金：{{zf.monthRent}}元
      押金：{{zf.deposit}}元<br><br>
      租约起始日期：{{zf.startDate}}
      租约终止日期：{{zf.endDate}}<br><br>
      还款周期：1个月
      还款账期：月<br><br>
      服务费：
      利息：{{zhuti.monthLimit}}元<br><br>
      待收租金合计<br><br>
      租房合同<br><br>

      租客身份证：<br><br>
      <el-button v-if="sf==2" @click="tong">审核通过</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <el-button v-if="sf==2" @click="bu">审核不通过</el-button>
      <span slot="footer" class="dialog-footer">
    <el-button @click="qx">取 消</el-button>
    <el-button type="primary" @click="qd">确 定</el-button>
  </span>
    </el-dialog>
    <!--    收房贷-->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="80%">
      <h1>|申请主题信息</h1><br>
      公寓名称：{{contas.premiseName}}<br><br>
      公司名称：{{contas.premiseName}}
      联系人：{{contas.premiseName}}<br><br>
      手机号：{{contas.signUserMobile}}
      申请时间：{{contas.conSignTime}}<br><br>
      法人姓名：{{contas.signUserName}}
      法人身份证：{{contas.signUserIdCard}}<br><br>
      公司地址：{{contas.cqAddress}}
      账户类型：{{contas.accountType}}<br><br>
      账户：{{contas.bankCardNumber}}
      备注：{{contas.remark}}<br>
      法人身份证：
      <h1>|贷款详细信息</h1><br>
      业主姓名：{{contas.ownerName}}
      业主身份证号：{{contas.ownerIdCard}}<br><br>
      业主手机号：{{contas.ownerMobile}}
      联系地址：{{contas.ownerAddress}}<br><br>
      备注：{{contas.remark}}<br><br>
      借款金额：{{zhuti.loanAmount}}元
      贷款利息：{{zhuti.reserve1}}元<br><br>
      一次性服务费：{{zhuti.reserve1}}元
      还款周期：1个月<br><br>
      租约起始日期：{{contas.leaseStartTime}}
      租约终止日期：{{contas.leaseEndTime}}<br><br>
      周期还款金额：{{zhuti.monthLimit}}元
      还款账期：{{zhuti.monthLimit}}月<br><br>
      房产证：<br><br>
      租房合同：<br><br>
      业主身份证：<br><br>
      业主银行卡：<br><br>
      维数公寓收取服务费:
      <el-input label="维数公寓收取服务费" style="width: 150px" v-if="sf==1"></el-input>
      <br><br>
      <el-button v-if="sf==2" @click="tong">审核通过</el-button>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <el-button v-if="sf==2" @click="bu">审核不通过</el-button>
      <span slot="footer" class="dialog-footer">
    <el-button @click="qx2">取 消</el-button>
    <el-button type="primary" @click="qd2">确定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import {getObject, listInstallment} from "@/api/finance/installment";
import { updateLoan} from "@/api/finance/loan";
import {getContract} from "@/api/contract/contract";

export default {
  name: "Installment",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房租分期申请表格数据
      installmentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,

      },
      zf: {},
      dialogVisible1: false,
      //收房贷审核
      sf: 1,
      dialogVisible: false,
      contas: {},
      zhuti: {},

      pd: ""

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房租分期申请列表 */
    getList() {
      this.loading = true;
      listInstallment(this.queryParams).then(response => {
        this.installmentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    cha(row) {

      if (row.jrProductType == 2) {
        console.log(row)
        getObject(row).then(response => {
          this.zhuti = response.data;
          this.dialogVisible = true;

        });
      } else if (row.jrProductType == 1) {
        getContract(row.cfContractId).then(response => {
          this.zf = response.data;
          this.dialogVisible1 = true;

        });
      }
    },
    //审核
    shenhe(row) {
      this.shenhes = row;
      this.cha(row);
      this.sf = 2;
      this.pd = row.applyState;
      console.log(this.pd)
    },
    tong() {
      //.
      // console.log(this.shenhes);
      //if(this.pd==2){
      console.log(this.pd)
      if (this.pd==1){
        this.shenhes.applyState = 2;
        updateLoan(this.shenhes).then(response => {
          console.log("审核：" + response)
          this.sf = 1
          this.dialogVisible = false;
          // alert(response.rows);
        })
      }else if (this.pd==2){
        this.shenhes.applyState = 4;
        updateLoan(this.shenhes).then(response => {
          console.log("审核：" + response)
          this.sf = 1
          this.dialogVisible = false;
          // alert(response.rows);
        })
      }

      //}


    },
    bu() {
      //if(this.pd==2){
      console.log(this.pd)
      if (this.pd==1){
        this.shenhes.applyState = 3;
        updateLoan(this.shenhes).then(response => {
          console.log("审核：" + response)
          this.sf = 1
          this.dialogVisible = false;
          // alert(response.rows);
        })
      }else if (this.pd==2){
        this.shenhes.applyState = 5;
        updateLoan(this.shenhes).then(response => {
          console.log("审核：" + response)
          this.sf = 1
          this.dialogVisible = false;
          // alert(response.rows);
        })
      }

    }
  }
};
</script>
